package drds.server.route.parser.core;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import drds.server.execute_engine.data_handling.RangeValue;
import drds.server.execute_engine.data_handling.Value;

/** 表名.列.范围 */
public class TableColumnValueSetMap {
	/** 表名.列.范围 */
	private Map<String, Map<String, Set<Value>>> tableColumnValueSetMapMap = new LinkedHashMap<String, Map<String, Set<Value>>>();

	public Map<String, Map<String, Set<Value>>> getTableColumnValueSetMapMap() {
		return tableColumnValueSetMapMap;
	}

	public void addValue(String tableName, String columnName, Object columnValue) {
		if (tableName == null) {
			throw new NullPointerException("tableName");
		}
		if (columnName == null) {
			throw new NullPointerException("columnName");
		}
		if (columnValue == null) {
			throw new NullPointerException("columnValue");
		}
		/** columnValueSetMap */
		Map<String, Set<Value>> columnValueSetMap = tableColumnValueSetMapMap.get(tableName);
		if (columnValueSetMap == null) {
			columnValueSetMap = new LinkedHashMap<String, Set<Value>>();
			tableColumnValueSetMapMap.put(tableName, columnValueSetMap);
		}
		/** valueSet */
		Set<Value> valueSet = columnValueSetMap.get(columnName);
		if (valueSet == null) {
			valueSet = new LinkedHashSet<Value>();
			tableColumnValueSetMapMap.get(tableName).put(columnName, valueSet);
		}
		/** set value */
		if (columnValue instanceof Object[]) {
			for (Object object : (Object[]) columnValue) {
				if (object == null) {
					throw new NullPointerException("object");
				}
				valueSet.add(new Value(object.toString()));
			}
		} else if (columnValue instanceof RangeValue) {
			valueSet.add(new Value((RangeValue) columnValue));
		} else {
			valueSet.add(new Value(columnValue.toString()));
		}
	}

}
